﻿#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
#include <string.h>
#include <assert.h>
//模拟实现strncat
//将source指向字符串的前num个字符追加到destination指向的字符串末尾，再追加⼀个 \0 字符
//如果source 指向的字符串的⻓度⼩于num的时候，只会将字符串中到\0 的内容追加到destination指向的字符串末尾
//返回值是指向dest的指针
char* mystrncat(char* dest, const char* src, size_t num)
{
	assert(dest && src);
	char* ret = dest;
	while (*dest)
	{
		dest++;
	}
	while (*src)
	{
		if (num == 0)
		{
			break;
		}
		*dest = *src;
		dest++;
		src++;
		num--;
	}
	*dest = '\0';
	return ret;
}

int main()
{
	char arr1[200] = "abcdef";
	char arr2[] = "h ehehehe";
	char* ret = mystrncat(arr1, arr2, 3);
	printf("%s\n", ret);
	return 0;
}